<?php

require_once 'server.php';

//echo "work';



function do_post_request($url, $postdata)
{
  $content = "";

  // Add post data to request.
  foreach($postdata as $key => $value)
  {
    $content .= "{$key}={$value}&";
  }

  $params = array('http' => array(
    'method' => 'POST',
    'header' => 'Content-Type: application/x-www-form-urlencoded',
    'content' => $content
  ));

  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);

  if (!$fp) {
    throw new Exception("Connection problem, {$php_errormsg}");
  }

  $response = @stream_get_contents($fp);
  if ($response === false) {
    throw new Exception("Response error, {$php_errormsg}");
  }

  return $response;
}

//echo "2b";
// Post variables.
$postdata = array(
  'blog' => 'test'
);

//do_post_request("http://localhost/~sarah_yang_22/server.php", $postdata);
//echo "<html><a href='server.php?blog/blog=test'>Data link</a></html>";
$api = new REST_API;
?>

